<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>添加代录人</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm.min.css">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm-extend.min.css">
    <link rel="stylesheet" href="/static/wx/css/reset.css">
    <link rel="stylesheet" href="/static/wx/css/main.css">
    <link rel="stylesheet" href="/static/wx/css/public_main.css">
</head>

<body>
<div class="page-group">
    <div class="page page-current" id="addRecorder">
        <!-- 主内容 -->
        <div class="content">
            <div class="bs-box">
                <div class="bs-box-content">
                    <div class="bs-box-inner">
                        <div class="bs-box-content-item">
                            <p class="size-m">代录人姓名</p>
                            <div>
                                <input class="size-m" type="text" placeholder="请填写代录人姓名" name="realName"/>
                            </div>
                        </div>
                        <div class="bs-box-content-item">
                            <p class="size-m">代录人手机号</p>
                            <div>
                                <input class="size-m" type="text" placeholder="请填写代录人手机号" name="mobile"/>
                            </div>
                        </div>
                        <div class="bs-box-content-item">
                            <p class="size-m">身份证</p>
                            <div>
                                <input class="size-m" type="text" placeholder="请填写代录人身份证号" name="cardNum"/>
                            </div>
                        </div>
                        <div class="bs-box-content-item width-link size-m">
                            <div>代录人类型</div>
                            <div>
                                <input id="recorderType" placeholder="请选择代录人类型"/>
                            </div>
                        </div>
                        <div class="bs-box-content-item">
                            <p class="size-m">单位名称</p>
                            <div>
                                <input class="size-m" type="text" placeholder="请填写代录人单位名称" name="rem_comname"/>
                            </div>
                        </div>
                        <div class="bs-box-content-item">
                            <p class="size-m">单位联系人</p>
                            <div>
                                <input class="size-m" type="text" placeholder="请填写代录人单位联系人" name="rem_link_name"/>
                            </div>
                        </div>
                        <div class="bs-box-content-item">
                            <p class="size-m">单位联系人电话</p>
                            <div>
                                <input class="size-m" type="text" placeholder="请填写代录人单位联系人电话" name="rem_link_phone"/>
                            </div>
                        </div>
                    </div>


                </div>
            </div>
            <div class="btn-box">
                <div class="my-btn size-m" id='sumbit'>
                    <span class="active">保存</span>
                </div>
            </div>
        </div>
    </div>
</div>
<script type='text/javascript' src='/static/wx/lib/sui/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/lib/sui/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/lib/sui/sm-extend.min.js' charset='utf-8'></script>
<script type='text/javascript' src="/static/wx/lib/vue/vue.min.js"></script>
</body>
<script>
    $(function () {
        var str = [];
        var typeArr = new Object();
        getType();
       //获取代录人类型
        function getType() {
            $.ajax({
                type: 'POST',
                url: "{:url('index/recorderType')}",
                data: {},
                dataType: 'json',
                async: false,
                success: function (Json) {
                    if (Json.code == 200) {
                        typeArr = Json.data.type_list;
                        for (var i = 0; i < typeArr.length; ++i) {
                            str.push(typeArr[i].name)
                        }
                    }
                }
            });
        }

        $("#recorderType").picker({
            cols: [
                {
                    textAlign: 'center',
                    values: str,
                    cssClass: 'picker-items-col-normal'
                }
            ]
        });
        $(document).on('click', '#sumbit', function () {
            var realName = $("input[ name='realName']").val();
            var mobile = $("input[ name='mobile']").val();
            var cardNum = $("input[ name='cardNum']").val();
            var rem_comname = $("input[ name='rem_comname']").val();
            var rem_link_name = $("input[ name='rem_link_name']").val();
            var rem_link_phone = $("input[ name='rem_link_phone']").val();
            var recorderType = $("#recorderType").val();
            var pattern = /^1[345678]\d{9}$/;
            //id 重新赋值
            if (realName.length == 0) {
                $.alert('请填写代录人姓名');
                return;
            }
            if (pattern.test(mobile) === false) {
                $.alert('请填写代录人手机号或者手机号格式错误');
                return;
            }
            if (cardNum.length == 0) {
                $.alert('请填写代录人身份证号');
                return;
            }
            if (recorderType.length ==0) {
                $.alert('请选择代录人类型');
                return;
            }
            for (var i = 0; i < typeArr.length; ++i) {
                if(recorderType ==typeArr[i].name){
                    recorderType =typeArr[i].id;
                }
            }
            if (rem_comname.length ==0) {
                $.alert('请填写单位名称');
                return;
            }
            if (rem_link_name.length ==0) {
                $.alert('请填写单位联系人');
                return;
            }
            if (pattern.test(rem_link_phone) === false) {
                $.alert('请填写单位联系人电话或者手机号格式错误');
                return;
            }
            $.ajax({
                type: 'POST',
                url: "{:url('insurer/bindOther')}",
                data: {
                    'mobile':mobile,
                    'realName': realName,
                    'recoder_type': recorderType,
                    'card_num': cardNum,
                    'rem_comname': rem_comname,
                    'rem_link_name': rem_link_name,
                    'rem_link_phone':rem_link_phone
                },
                dataType: 'json',
                success: function (Json) {
                    if (Json.code == 200) {
                        $.alert('保存成功');
                        location.href="{:url('index/index')}";
                    } else {
                        $.alert(Json.msg);
                    }
                }
            });





        });

    });
</script>

</html>